package com.peopledelete.controller;

import com.peopledelete.pojo.X;
import com.peopledelete.service.XService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author cyt
 * @create 2020-06-15 15:34
 */
@Slf4j
@RestController
public class Xcontroller {

    @Autowired
    XService xService;

    /**
     * 存入 预测的因变量
     *
     * @param x
     * @return
     */
    @ResponseBody
    @RequestMapping("/savaXinfo")
    public String saveXinfo(@RequestBody X x) {
        // 获得明天的日期。
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date today = new Date();//获取今天的日期
        Calendar c = Calendar.getInstance();
        c.setTime(today);
        c.add(Calendar.DAY_OF_MONTH, 1);
        Date tomorrow = c.getTime();//这是明天
        // String format = sdf.format(tomorrow);
        try {
            System.out.println("x: " + x);
            x.setDate(tomorrow);
            xService.save(x);
            return "提交成功";
        } catch (Exception e) {
            log.info(e.getMessage());
            return "提交失败";
        }
    }
}
